<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%String path = request.getContextPath();%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <c:set var="ctx" value="${pageContext.request.contextPath}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>资管机构管理</title>
    <jsp:include page="../../import.jsp" flush="true"/>
</head>
<script type="text/javascript">
    var COMBO_GRIDAdd=null;//配置
    var COMBO_GRIDMdf=null;//配置
    var COMBO_GRIDAddPrj=null;
    var COMBO_GRIDMdfPrj=null;
    var certTypCdList = null;
    var grid = null;
    var addGSData_s = {};
    $(function () {
        var _url = '<%=path%>/custpay/payInsRcvAcc/initList.do';
        $("#ligergrid1").ligerGrid({
            url: _url,
            method: 'get',
            columns: [
                {display: '机构名称', name: 'insNm', align: 'left', width: 200},
                {display: '机构账号', name: 'insAccNoId', align: 'left', width: 200},
                {display: '项目名称', name: 'prjNm', align: 'left', width: 200},
                {display: '支付平台', name: 'payChlCdNm', align: 'left', width: 100},
                {display: '交易类型', name: 'transTypCdNm', align: 'left', width: 100},
                {display: '支付平台商户号', name: 'payChlBizNo', align: 'left', width: 100},
                {display: '支付秘钥', name: 'payKey', align: 'left', width: 100},
                {display: '创建时间', name: 'crtTm', align: 'left', width: 150, render: renderDate},
                {
                    display: '操作', width: 150, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var b = '<a class="sq-button-hasicon" href="javascript:change(' + "'" + rowdata.id + "'" + ')"><i class="sqBtnIco_4"></i>修改</a>';
                        var c = '<a class="sq-button-hasicon" href="javascript:del(' + "'" + rowdata.id + "'" + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        var end = b + c;
                        return end;
                    }
                }
            ],
            pageSize: 10,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: '100%',
            heightDiff: -2,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            onBeforeShowData: function () {
                var grid = this;
                grid.collapsedRows = [];
            }
        });
        grid = liger.get("ligergrid1");
        grid.setHeight(100);
        $("#searchBar").ligerForm();

        $("#searchBtn").click(function (event) {
            var form = new liger.get("searchBar");
            var data = form.getData();
            for (name in data) {
                grid.setParm(name, data[name]);
            }
            grid.reload($('.pcontrol input', grid.toolbar).val());
        });
        $("#addBtn").click(function (event) {
            $.ligerDialog.open({
                width: 450,
                //top: 100,
                title: '新增资管机构信息',
                target: $("#add_Html"),
                onHideDialog: function () {
                    clearLigerForm("add_form");
                }
            });
            var ligerForm = $("#add_form").ligerForm({validate: true});
        });
        $("#saveNew_Btn").click(function (event) {
            var form = liger.get("add_form");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }
            var data = form.getData();
            data.isValid = "1";//默认有效
            data.lstTyp = "1";//默认白名单
            $.ligerDialog.hide();
            //以下应该有一段Ajax交互
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: '<%=path%>/custpay/payInsRcvAcc/add.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        bankHeadQ = null;
                        $("#resetBtn").click();
                        $("#searchBtn").click();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
        $("#saveChange_Btn").click(function (event) {
            var form = liger.get("change_form");
            if (!form.valid()) {
                $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO, SQ_type: "warning"});
                return false; //验证不通过，不执行以下代码
            }

            var data = form.getData();
            $.ligerDialog.hide();
            //以下应该有一段Ajax交互
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: data,
                url: '<%=path%>/custpay/payInsRcvAcc/modify.do?id=' + addGSData_s.id,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        bankHeadQ = null;
                        $("#resetBtn").click();
                        $("#searchBtn").click();
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }


                }
            });
        });
        $("#clearBtn").click(function (event) {
            $("#resetBtn").click();  //重置 input-text
        });

        COMBO_GRIDAdd =$("#insId").ligerComboBox({
            selectBoxWidth: 380,
            selectBoxHeight: 240,
//            valueFieldID: 'mp',
            valueField: 'id',
            textField: 'fundRasInsNm',
            grid: {
                columns: [
                    { display: '机构', name: 'fundRasInsNm', minWidth: 300 }
                ],
                switchPageSizeApplyComboBox: false,
                url : '<%=path%>/custpay/payInsRcvAcc/initFundList.do',
                method: 'get',
                root:'rows',
                record:'total',
                pageSize: 10,
                cssClass: "SMALL_grid",
                checkbox: false,
                frozen: false,
                onAfterShowData: function (currentData) {//alert(1);
                }
            },
            delayLoadGrid: true, //点击的时候出发
            onChangeValue: function (value) {},
            onSelected : function(value,text){
                $("#insNm").val(text);
                getBankAcc(value,'insAccNoId');
            }
        });

        COMBO_GRIDMdf =$("#insIdEdit").ligerComboBox({
            selectBoxWidth: 380,
            selectBoxHeight: 240,
//            valueFieldID: 'mp',
            valueField: 'id',
            textField: 'fundRasInsNm',
            grid: {
                columns: [
                    { display: '机构', name: 'fundRasInsNm', minWidth: 300 }
                ],
                switchPageSizeApplyComboBox: false,
                url : '<%=path%>/custpay/payInsRcvAcc/initFundList.do',
                method: 'get',
                root:'rows',
                record:'total',
                pageSize: 10,
                cssClass: "SMALL_grid",
                checkbox: false,
                frozen: false,
                onAfterShowData: function (currentData) {//alert(1);
                }
            },
            delayLoadGrid: true, //点击的时候出发
            onChangeValue: function (value) {},
            onSelected : function(value,text){
                $("#insNmEdit").val(text);
                getBankAcc(value,'insAccNoIdEdit');
            }
        });

        COMBO_GRIDAddPrj =$("#prjId").ligerComboBox({
            selectBoxWidth: 380,
            selectBoxHeight: 240,
//            valueFieldID: 'mp',
            valueField: 'id',
            textField: 'fncprjnm',
            grid: {
                columns: [
                    { display: '项目', name: 'fncprjnm', minWidth: 300 }
                ],
                switchPageSizeApplyComboBox: false,
                url : '<%=path%>/custpay/payInsRcvAcc/initPrjList.do',
                method: 'get',
                root:'rows',
                record:'total',
                pageSize: 10,
                cssClass: "SMALL_grid",
                checkbox: false,
                frozen: false,
                onAfterShowData: function (currentData) {//alert(1);
                }
            },
            delayLoadGrid: false, //点击的时候出发
            onChangeValue: function (value) {},
            onSelected : function(value,text){
            }
        });

        COMBO_GRIDMdfPrj =$("#prjIdEdit").ligerComboBox({
            selectBoxWidth: 380,
            selectBoxHeight: 240,
//            valueFieldID: 'mp',
            valueField: 'id',
            textField: 'fncprjnm',
            grid: {
                columns: [
                    { display: '项目', name: 'fncprjnm', minWidth: 300 }
                ],
                switchPageSizeApplyComboBox: false,
                url : '<%=path%>/custpay/payInsRcvAcc/initPrjList.do',
                method: 'get',
                root:'rows',
                record:'total',
                pageSize: 10,
                cssClass: "SMALL_grid",
                checkbox: false,
                frozen: false,
                onAfterShowData: function (currentData) {//alert(1);
                }
            },
            delayLoadGrid: true, //点击的时候出发
            onChangeValue: function (value) {},
            onSelected : function(value,text){
            }
        });
    });
    function getBankAcc(id, elementId) {
        if (elementId == 'insAccNoId') {
            COMBO_GRIDAddPrj.grid.setParm("fncinsid",id);
            COMBO_GRIDAddPrj.grid.reload();
        } else if (elementId == 'insAccNoIdEdit') {
            COMBO_GRIDMdfPrj.grid.setParm("fncinsid",id);
            COMBO_GRIDMdfPrj.grid.reload();
        }
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/custpay/payInsRcvAcc/getBankAcc.do?id=' + id,
            success: function (msg) {
                if (msg.success == 1) {
                    //主运输货物
                    var insacc = $("#"+elementId);
                    if(insacc.length){
                        $("#"+elementId).empty();
//                        $("#"+elementId).append("<option value=''>请选择</option>");
                        $.each(msg.data,function(index,obj) {
                            var option = "<option value='"+obj.banAccNum+"'>"+obj.accNm+"-"+obj.banAccNm+"-"+obj.banAccNum+"</option>";
                            $(option).appendTo("#"+elementId);
                        });
                        $("#"+elementId).add_ligerFormEditor();
                    }
                    SetIframe_height();
                    liger.get(elementId).setSelect();
                    if ("insAccNoIdEdit"==elementId) {
                        liger.get(elementId).setValue(addGSData_s.insAccNoId);
                    }
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    //修改数据
    function change(_id) {
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: '<%=path%>/custpay/payInsRcvAcc/getById.do?id=' + _id,
            success: function (msg) {
                if (msg.success == 1) {
                    //$.ligerDialog.success(msg.info)
                    openChange();//弹出修改框
                    setData(msg.data);//设置数据
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
    function openChange() {
        $.ligerDialog.open({
            width: 450,
//            top: 100,
            title: '修改资管机构信息',
            target: $("#change_Html"),
            onHideDialog: function () {
                clearLigerForm("change_form");
            }
        });
        var ligerForm = $("#change_form").ligerForm({validate: true});
    }
    //设置页面数据
    function setData(data) {
        var form = liger.get("change_form");
        addGSData_s.id = data.id;
        addGSData_s.insAccNoId = data.insAccNoId;
        COMBO_GRIDMdf._setValue(data.insId, data.insNm);
        form.setData({
            insAccNoId: data.insAccNoId,
            payChlCd: data.payChlCd,
            transTypCd: data.transTypCd,
            payChlBizNo: data.payChlBizNo,
            payKey: data.payKey
        });
    }
    //删除数据
    function del(_id) {
        if (!_id)return;
        $.ligerDialog.confirm('确定删除吗?', function (flag) {
            if (flag == false)return;
            var wait_dialog;
            $.ajax({
                type: 'get',
                dataType: 'json',
                url: '<%=path%>/custpay/payInsRcvAcc/removeById.do?id=' + _id,
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        grid.reload($('.pcontrol input', grid.toolbar).val());
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }
    //格式化时间
    function renderDate(rowdata, index, value) {
        var dateStr = "";
        if (null != value) {
            var date = new Date(value);
            dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DDHHMMSS);
        }
        return dateStr;
    }
</script>

<body class="iframeBody">
<div class="Wrapper">
    <div class="searchArea">
        <form id="searchBar">
            <div class="fieldset1 clearFix">
                <div class="fieldBox">
                    <div class="label">机构名称</div>
                    <div class="field">
                        <input name="insNm" id="insNmSearch" type="text" class="ui-textbox" value="">
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">支付平台</div>
                    <div class="field">
                        <select name="payChlCd" id="payChlCdSearch" data-value=" ">
                            <option value=" " seleted>请选择</option>
                            <c:forEach items="${payChlCdList }" var="kv">
                                <option value="${kv.key }">${kv.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_100">
                    <div class="label">交易类型</div>
                    <div class="field">
                        <select name="transTypCd" id="transTypCdSearch" data-value=" ">
                            <option value=" " seleted>请选择</option>
                            <c:forEach items="${transTypCdlist }" var="kv">
                                <option value="${kv.key }">${kv.value }</option>
                            </c:forEach>
                        </select>
                    </div>
                </div>
                <div class="clearFix"></div>
                <div class="btnsBox formBtns notRight">
                    <span id="searchBtn" class="sq-button-round">查询</span>
                    <span id="clearBtn" class="sq-button-round">清空</span>
                    <span id="addBtn" class="sq-button-round">新增</span>

                    <input id="resetBtn" type="reset" value="重置" class="l-button l-button-reset Hide"/>
                </div>
            </div>
        </form>
    </div>
</div>
<div id="ligergrid1" class="sq-grid"></div>

<!-- 增加资管机构信息弹出框 -->
<div id="add_Html" style="display:none">
    <form id="add_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100_auto">
                <div class="label">机构</div>
                <div class="field">
                    <input type="text" name="insId" id="insId" ltype="combobox" placeholder="请选择" ligerui="width:250"/>
                    <input type="text" name="insNm" id="insNm" style="display: none" value="">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">融资机构账户</div>
                <div class="field">
                    <select name="insAccNoId" id="insAccNoId" data-value=" " ligerui="width:250">
                        <option value=''>请选择</option>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">项目</div>
                <div class="field">
                    <input type="text" name="prjId" id="prjId" ltype="combobox" placeholder="请选择" ligerui="width:250"/>
                    <input type="text" name="prjNm" id="prjNm" style="display: none" value="">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">支付平台</div>
                <div class="field">
                    <select name="payChlCd" id="payChlCd" data-value=" " ligerui="width:250">
                        <option value=" " seleted>请选择</option>
                        <c:forEach items="${payChlCdList }" var="kv">
                            <option value="${kv.key }">${kv.value }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">交易类型</div>
                <div class="field">
                    <select name="transTypCd" id="transTypCd" data-value=" " ligerui="width:250">
                        <option value=" " seleted>请选择</option>
                        <c:forEach items="${transTypCdlist }" var="kv">
                            <option value="${kv.key }">${kv.value }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">支付平台商户号</div>
                <div class="field">
                    <input name="payChlBizNo" id="payChlBizNo" type="text" class="ui-textbox" value="" ligerui="width:250">
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">支付秘钥</div>
                <div class="field">
                    <input name="payKey" id="payKey" type="text" class="ui-textbox" value="" ligerui="width:250">
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveNew_Btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>

<!-- 修改资管机构信息弹出框 -->
<div id="change_Html" style="display:none">
    <form id="change_form">
        <div class="fieldset1 tabel_col tabel_col_1 clearFix">
            <div class="fieldBox col_100_auto">
                <div class="label">项目</div>
                <div class="field">
                    <input type="text" name="insId" id="insIdEdit" ltype="combobox" placeholder="请选择" ligerui="width:250"/>
                    <input type="text" name="insNm" id="insNmEdit" style="display: none" value="">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">融资机构账户</div>
                <div class="field">
                    <select name="insAccNoId" id="insAccNoIdEdit" data-value=" " ligerui="width:250">
                        <option value=''>请选择</option>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">项目</div>
                <div class="field">
                    <input type="text" name="prjId" id="prjIdEdit" ltype="combobox" placeholder="请选择" ligerui="width:250"/>
                    <input type="text" name="prjNm" id="prjNmEdit" style="display: none" value="">
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">支付平台</div>
                <div class="field">
                    <select name="payChlCd" id="payChlCdEdit" data-value=" " ligerui="width:250">
                        <option value=" " seleted>请选择</option>
                        <c:forEach items="${payChlCdList }" var="kv">
                            <option value="${kv.key }">${kv.value }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">交易类型</div>
                <div class="field">
                    <select name="transTypCd" id="transTypCdEdit" data-value=" " ligerui="width:250">
                        <option value=" " seleted>请选择</option>
                        <c:forEach items="${transTypCdlist }" var="kv">
                            <option value="${kv.key }">${kv.value }</option>
                        </c:forEach>
                    </select>
                    <span class="requiredSymbol">*</span>
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">支付平台商户号</div>
                <div class="field">
                    <input name="payChlBizNo" id="payChlBizNoEdit" type="text" class="ui-textbox" value="" ligerui="width:250">
                </div>
            </div>
            <div class="fieldBox col_100_auto">
                <div class="label">支付秘钥</div>
                <div class="field">
                    <input name="payKey" id="payKeyEdit" type="text" class="ui-textbox" value="" ligerui="width:250">
                </div>
            </div>
        </div>
        <div class="btnsBox">
            <span id="saveChange_Btn" class="sq-button sq-button-hasicon"><i class="sqBtnIco_10"></i>保存</span>
        </div>
    </form>
</div>
</body>
</html>